﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SGTD.Entidades;
using SGTD.COM;

namespace SGTD.Controllers
{
    public class FichaTramiteController : Controller
    {
        //
        // GET: /FichaTramite/

        public ActionResult Index()
        {
            return View();
        }


        [HttpPost()]
        public ContentResult GetClienteByDNI(FormCollection clientData)
        {
            string html = "";
            if (clientData["value"] == null || clientData["value"] == "")
            {
                return Content("Not Found");
            }
            clsCliente objCliente = clsGestorFichaTramite.getClienteByDNI(Convert.ToInt32(clientData["value"]));
            if (objCliente != null)
            {
                html += objCliente.IdCliente + "%" + objCliente.Nombres + "%";
                List<clsFichaTramite> objList = clsGestorFichaTramite.getFichaTramiteListByDNI(Convert.ToString(clientData["value"]));
                foreach (clsFichaTramite obj in objList)
                {
                    html += "<tr>";
                    html += "<td>" + obj.IdFichaTramite + "</td>";
                    html += "<td>" + obj.FechaEnvio + "</td>";
                    html += "<td>" + obj.TipoFichaTramite.IdTipoFichaTramite + "</td>";
                    html += "<td><a href=# class='aEditar'>Edit</a></td>";
                    html += "<td><a href=# class='aDelete'>Delete</a></td>";
                    html += "</tr>";
                }
            }
            else
            {
                html = "Not Found";
            }
            return Content(html);
        }
        [HttpPost()]
        public ContentResult SaveCliente(FormCollection clientData)
        {
            clsCliente obj = new clsCliente();
            obj.Apellidos = clientData["Apellidos"];
            obj.Nombres = clientData["Nombres"];
            obj.DNI = clientData["DNI"];
            obj.Direccion = clientData["Direccion"];
            obj.Telefono = clientData["Telefono"];
            if (clsGestorFichaTramite.saveCliente(obj))
            {
                return Content("Success");
            }
            else
            {
                return Content("Error");
            }
        }

    }
}
